﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aij1.BLL;
using Aij1.Cms;
using Aij1.Utils;
using System.Data;
using Aij1.Model;
using System.Text;

namespace Aij1
{
    public partial class Search : BasePage
    {
        protected WebPager WPager;
        protected string Keyword;
        protected string Tips;
        protected void Page_Load(object sender, EventArgs e)
        {
            Keyword = CommOp.ToStr(Request.QueryString["Keyword"]);
            Keywords = "新闻搜索;相册搜索;" + Keyword;
            Description = "简单实用的新闻和相册搜索系统,搜索全站";

            WPager = new WebPagerSEO()
            {
                KeyId = "Oid",
                OrderBy = "DisplayTime DESC",
                Query = @"SELECT DISTINCT a.Oid,a.Title,a.DisplayTime,a.SetTopTime,a.Intro,a.AType,p.SnapShotUrl,p.SnapShotWidth,p.SnapShotHeight,c.Oid as CategoryId,c.Title as CategoryTitle,c.AType as CategoryType FROM 
A_Article a LEFT JOIN A_Photo p ON a.SamplePhotoId=p.Oid LEFT JOIN A_Category c ON A.CategoryId=c.Oid 
LEFT JOIN A_ArticleKeyword ak ON a.Oid=ak.ArticleId LEFT JOIN A_Keyword k 
ON k.Oid=ak.KeywordId
WHERE a.GCRecord IS NULL AND Status=3 AND (a.Title LIKE @Keyword OR a.Intro LIKE @Keyword OR c.Title LIKE @Keyword OR k.Title LIKE '%'+@Key+'%')",
                PageSize = 20,
            };

            PageName = String.Format("\"{0}\"的搜索结果", Keyword);
            PageName += (WPager.PageIndex <= 1) ? "" : " 第" + WPager.PageIndex + "页";
            
            if (String.IsNullOrEmpty(Keyword))
            {
                Tips = "请输入搜索关键词.";
                return;
            }
            if (Keyword.Length < 2)
            {
                Tips = "请输入至少两个字符的关键词.";
                return;
            }

            IDataReader reader = ArticleData.GetPagedNewsList(XpoSession, WPager, Keyword);
            repNews.DataSource = reader;
            repNews.DataBind();
            Tips = String.Format("\"<b>{0}</b>\"的搜索结果,共找到{1}条。", Keyword, WPager.RowNum);

        }
    }
}